package github.sf.fw.tools.config;

import github.sf.fw.utils.StrUtil;

/**
 * @author zhoup
 * @since 2023/4/18
 */
public class SystemConfig {
    private final static String DataCenterId = "DataCenterId";
    private final static String DataWordId = "DataWorkId";

    @SuppressWarnings("unchecked")
    public static String getProp(String key, String value) {
        if (System.getProperties() == null) {
            return value;
        }
        String val = System.getProperty(key);
        return val == null ? value : val;
    }

    public static String getOrDefault(String key, String def) {
        String envValue = System.getenv(DataCenterId);
        if (StrUtil.isEmpty(envValue)) {
            return getProp(key, def);
        }
        return envValue;
    }

    public static long getDataCenterId() {
        return Long.parseLong(getOrDefault(SystemConfig.DataCenterId, "1"));
    }

    public static long getDataWorkId() {
        return Long.parseLong(getOrDefault(SystemConfig.DataWordId, "1"));
    }

    public static void set(String key, Object value) {
        System.getProperties().put(key, value);
    }


}
